package cn.kgc.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Utils {
    //加密密码
    public static String enCode(String oldCode){
        StringBuilder sb=null;
        try {
            MessageDigest newCode=MessageDigest.getInstance("md5");
            byte[] bytes=newCode.digest(oldCode.getBytes());
            sb=new StringBuilder();
            int temp=0;
            for (byte b:bytes) {
                temp=b;
                if (temp<0){
                    temp+=256;
                }
                sb.append(Integer.toHexString(temp));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return "";
        }
        return sb.toString();
    }
}
